<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>自定义菜单</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<jsp:include page="../inc.jsp"></jsp:include>
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/assets/css/menu/styles.css"/>
<style>

*,
*:after,
*:before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

.switch {
  margin: 50px auto;
  position: relative;
}

.switch label {
  width: 100%;
  height: 100%;
  position: relative;
  display: block;
}

.switch input {
  top: 0; 
  right: 0; 
  bottom: 0; 
  left: 0;
  opacity: 0;
  z-index: 100;
  position: absolute;
  width: 100%;
  height: 100%;
  cursor: pointer;
}
#u19543_input{
	top: -75px;
}
#u19543 {
    top: 780px;
}
</style>
  <script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/jquery.dtGrid.v1.1.9/dependents/bootstrap/js/popover.js"></script>
</head>
  <body>
    <!-- 手机(图片) -->
      <div id="u19482" class="ax_default _图片 shadow-cave" >
        <img id="u19482_img" class="img shadow" src="${pageContext.request.contextPath}/resources/images/自定义菜单/u19482.png"/>
        <!-- Unnamed () -->
        <div id="u19483" class="text" style="display: none; visibility: hidden">
          <p><span></span></p>
        </div>
      </div>

      <!-- 小键盘 (图片) -->
      <div id="u19484" class="ax_default _图片">
        <img id="u19484_img" class="img " src="${pageContext.request.contextPath}/resources/images/自定义菜单/u19484.png"/>
        <!-- Unnamed () -->
        <div id="u19485" class="text" style="display: none; visibility: hidden">
          <p><span></span></p>
        </div>
      </div>

      <!-- 底部一级菜单 (菜单) -->
      <div id="u19486" class="ax_default">
        <img id="u19486_menu" class="img " src="${pageContext.request.contextPath}/resources/images/自定义菜单/u19486_menu.png" alt="u19486_menu"/>

        <!-- Unnamed (表格) -->
        <div id="u19487" class="ax_default">

          <!-- 第一个 (Menu Item) -->
          <div id="u19488" class="ax_default menu_item" data-toggle="popover" data-animation="true" onClick="addBottomMenu(1);">
          	<input type="hidden" value="" name="childMenu">
          	<input type="hidden" value="" name="childMenuIds">
          	<input type="hidden" value="" name="childUrl">
          	<input type="hidden" value="" name="childInfo">
          	<input type="hidden" value="" name="childType">
          	<input type="hidden" value="" id="itemId1" name="itemId">
          	<input type="hidden" value="" id="type1" name="type">
          	<input type="hidden" value="" id="url1" name="url">
          	<input type="hidden" value="" id="info1" name="info">
            <img id="u19488_img" class="img " src="${pageContext.request.contextPath}/resources/images/自定义菜单/u19488.png"/>
            <!-- Unnamed () -->
            <div id="u19489" class="text" style="visibility: visible;" >
              <p><span>+</span></p>
            </div>
          </div>
          

          <!-- 第二个 (Menu Item) -->
          <div id="u19490" class="ax_default menu_item" data-toggle="popover" data-animation="true" onClick="addBottomMenu(2);">
          	<input type="hidden" value="" name="childMenu">
          	<input type="hidden" value="" name="childMenuIds">
          	<input type="hidden" value="" name="childUrl">
          	<input type="hidden" value="" name="childInfo">
          	<input type="hidden" value="" name="childType">
          	<input type="hidden" value="" id="itemId2" name="itemId">
          	<input type="hidden" value="" id="type2" name="type">
          	<input type="hidden" value="" id="url2" name="url">
          	<input type="hidden" value="" id="info2" name="info">
            <img id="u19490_img" class="img " src="${pageContext.request.contextPath}/resources/images/自定义菜单/u19490.png"/>
            <!-- Unnamed () -->
            <div id="u19491" class="text" style="visibility: visible;" >
              <p><span>+</span></p>
            </div>
          </div>

          <!-- 第三个 (Menu Item) -->
          <div id="u19492" class="ax_default menu_item" data-toggle="popover" data-animation="true" onClick="addBottomMenu(3);">
          	<input type="hidden" value="" name="childMenu">
          	<input type="hidden" value="" name="childMenuIds">
          	<input type="hidden" value="" name="childUrl">
          	<input type="hidden" value="" name="childInfo">
          	<input type="hidden" value="" name="childType">
          	<input type="hidden" value="" id="itemId3" name="itemId">
          	<input type="hidden" value="" id="type3" name="type">
          	<input type="hidden" value="" id="url3" name="url">
          	<input type="hidden" value="" id="info3" name="info">
            <img id="u19492_img" class="img " src="${pageContext.request.contextPath}/resources/images/自定义菜单/u19492.png"/>
            <!-- Unnamed () -->
            <div id="u19493" class="text" style="visibility: visible;" >
              <p><span>+</span></p>
            </div>
          </div>
        </div>
      </div>
		
      <!-- 新增子菜单 (动态面板) -->
      <div id="u19494" class="ax_default"  data-label="新增子菜单" style="border-left:2px solid;display:none;">
      	<input type="hidden" value="" name="num">
      	<input type="hidden" value="" name="menuId">
      	<input type="hidden" value="" name="childMenuId">
        <div id="u19494_state0" class="panel_state" data-label="一级菜单">
          <div id="u19494_state0_content" class="panel_state_content">

            <!-- Unnamed (矩形) -->
            <div id="u19495" class="ax_default box_1">
              <div id="u19495_div" class=""></div>
            </div>

            <!-- Unnamed (矩形) -->
            <div id="u19497" class="ax_default _三级标题">
              <div id="u19497_div" class=""></div>
              <!-- Unnamed () -->
              <div id="u19498" class="text" style="visibility: visible;">
                <p><span>编辑菜单名</span></p>
              </div>
            </div>

            <!-- Unnamed (文本框) -->
            <div id="u19499" class="ax_default _文本框">
              <input id="u19499_input" type="text" value=""/>
            </div>

            <!-- 菜单动作 (矩形) -->
            <div id="u19504" class="ax_default _三级标题" data-label="菜单动作">
              <div id="u19504_div" class=""></div>
              <!-- Unnamed () -->
              <div id="u19505" class="text" style="visibility: visible;">
                <p><span>菜单动作</span></p>
              </div>
            </div>

            <!-- 发送到 (矩形) -->
            <div id="u19506" class="ax_default _三级标题" data-label="发送到" onClick="changeChildToClick();">
              <div id="u19506_div" class=""></div>
              <!-- Unnamed () -->
              <div id="u19507" class="text">
                <p><span>发送到</span></p>
              </div>
            </div>

            <!-- Unnamed (垂直线) -->
            <div id="u19508" class="ax_default line">
              <img id="u19508_img" class="img " src="${pageContext.request.contextPath}/resources/images/自定义菜单/u19508.png"/>
              <!-- Unnamed () -->
              <div id="u19509" class="text" style="display: none;">
                <p><span></span></p>
              </div>
            </div>

            <!-- 跳转链接 (矩形) -->
            <div id="u19510" class="ax_default _三级标题" data-label="跳转链接" onClick="changeChildToView();">
              <div id="u19510_div" class=""></div>
              <!-- Unnamed () -->
              <div id="u19511" class="text">
                <p><span>跳转到链接</span></p>
              </div>
            </div>

            <!-- 菜单动作 (动态面板) -->
            <div id="u19512" class="ax_default" data-label="菜单动作">
              <div id="u19512_state0" class="panel_state" data-label="发送消息">
                <div id="u19512_state0_content" class="panel_state_content">

                  <!-- Unnamed (多行文本框) -->
                  <div id="u19513" class="ax_default text_area">
                    <textarea id="u19513_input"></textarea>
                  </div>
                </div>
              </div>
              <div id="u19512_state1" class="panel_state" data-label="跳转到链接" style="display: none;">
                <div id="u19512_state1_content" class="panel_state_content">

                  <!-- Unnamed (文本框) -->
                  <div id="u19514" class="ax_default _文本框">
                    <input id="u19514_input" type="text" value="" placeholder="请输入以http://开头的网址"/>
                  </div>
                </div>
              </div>
            </div>

            <!-- Unnamed (提交按钮) -->
            <div id="u19515" class="ax_default _提交按钮" onClick="hideModel_();">
              <input id="u19515_input" type="submit" value="取消"/>
            </div>

            <!-- Unnamed (提交按钮) -->
            <div id="u19516" class="ax_default _提交按钮" onClick="saveChildMenu();">
              <input id="u19516_input" type="submit" value="保存"/>
            </div>
          </div>
        </div>
      </div>

	   <!-- 编辑菜单 (动态面板) -->
      <div id="u19494_" class="ax_default"  data-label="编辑菜单" style="border-left:2px solid;display:none;">
      	<input type="hidden" value="" id="num">
      	<input type="hidden" value="" id="menuId">
        <div id="u19494_state0_" class="panel_state" data-label="一级菜单">
          <div id="u19494_state0_content_" class="panel_state_content">

            <!-- Unnamed (矩形) -->
            <div id="u19495_" class="ax_default box_1">
              <div id="u19495_div_" class=""></div>
              <!-- Unnamed () -->
              <div id="u19496_" class="text" style="display: none; visibility: hidden">
                <p><span></span></p>
              </div>
            </div>

            <!-- Unnamed (矩形) -->
            <div id="u19497_" class="ax_default _三级标题">
              <div id="u19497_div_" class=""></div>
              <!-- Unnamed () -->
              <div id="u19498_" class="text" style="visibility: visible;">
                <p><span>编辑菜单名</span></p>
              </div>
            </div>

            <!-- Unnamed (文本框) -->
            <div id="u19499_" class="ax_default _文本框">
              <input id="u19499_input_" type="text" value=""/>
            </div>

            <!-- 开启子菜单 (图片) -->
            <div id="u19500_" class="ax_default _图片" onClick="openOrclosePopover();">
              <div class="switch demo4switch">
					<input type="checkbox" id="box">
					<label><i></i></label>
				</div>
            </div>

            <!-- 开启子菜单 (矩形) -->
            <div id="u19502_" class="ax_default _三级标题">
              <div id="u19502_div_" class=""></div>
              <!-- Unnamed () -->
              <div id="u19503_" class="text" style="visibility: visible;">
                <p><span>开启子菜单</span></p>
              </div>
            </div>

            <!-- 菜单动作 (矩形) -->
            <div id="u19504_" class="ax_default _三级标题" data-label="菜单动作">
              <div id="u19504_div_" class=""></div>
              <!-- Unnamed () -->
              <div id="u19505_" class="text" style="visibility: visible;">
                <p><span>菜单动作</span></p>
              </div>
            </div>

            <!-- 发送到 (矩形) -->
            <div id="u19506_" class="ax_default _三级标题" data-label="发送到" onClick="changeToClick();">
              <div id="u19506_div_" class=""></div>
              <!-- Unnamed () -->
              <div id="u19507_" class="text" style="visibility: visible;">
                <p><span>发送到</span></p>
              </div>
            </div>

            <!-- Unnamed (垂直线) -->
            <div id="u19508_" class="ax_default line">
              <img id="u19508_img_" class="img " src="${pageContext.request.contextPath}/resources/images/自定义菜单/u19508.png"/>
              <!-- Unnamed () -->
              <div id="u19509_" class="text" style="display: none; visibility: hidden">
                <p><span></span></p>
              </div>
            </div>

            <!-- 跳转链接 (矩形) -->
            <div id="u19510_" class="ax_default _三级标题" data-label="跳转链接" onClick="changeToView();">
              <div id="u19510_div_" class=""></div>
              <!-- Unnamed () -->
              <div id="u19511_" class="text" style="visibility: visible;">
                <p><span>跳转到链接</span></p>
              </div>
            </div>

            <!-- 菜单动作 (动态面板) -->
            <div id="u19512_" class="ax_default" data-label="菜单动作">
              <div id="u19512_state0_" class="panel_state" data-label="发送消息">
                <div id="u19512_state0_content_" class="panel_state_content">

                  <!-- Unnamed (多行文本框) -->
                  <div id="u19513_" class="ax_default text_area">
                    <textarea id="u19513_input_"></textarea>
                  </div>
                </div>
              </div>
              <div id="u19512_state1_" class="panel_state" data-label="跳转到链接" style="display: none;">
                <div id="u19512_state1_content_" class="panel_state_content">

                  <!-- Unnamed (文本框) -->
                  <div id="u19514_" class="ax_default _文本框">
                    <input id="u19514_input_" type="text" value="" placeholder="请输入以http://开头的网址"/>
                  </div>
                </div>
              </div>
            </div>

            <!-- Unnamed (提交按钮) -->
            <div id="u19515_" class="ax_default _提交按钮" onClick="hideModel();">
              <input id="u19515_input_" type="submit" value="取消"/>
            </div>

            <!-- Unnamed (提交按钮) -->
            <div id="u19516_" class="ax_default _提交按钮" onClick="saveBottomButton();">
              <input id="u19516_input_" type="submit" value="保存"/>
            </div>
          </div>
        </div>
      </div>

      <!-- Unnamed (提交按钮) -->
      <div id="u19543" class="ax_default _提交按钮">
        <input id="u19543_input" type="submit" value="发布" onClick="updateMenu();"/>
      </div>
      
      
<script type="text/javascript">
	 $(function(){
	 	initMenus();
	 });	
	 
	 function initMenus(){
	 	var url="${pageContext.request.contextPath}/menu/show.action";
	 	$.get(url,function(result){
	 		if (result && result.length > 0){
					for (var i=0; i < result.length; i++){
						console.log(result[i].parentId)
						if (result[i].parentId == 0){
							var element = $('[data-toggle="popover"]:eq('+(i)+')');
		       	 				element.find("span").html(result[i].name);
		       	 				element.find("input[name='itemId']").val(result[i].id);
		       	 				element.find("input[name='type']").val(result[i].type);
		       	 				element.find("input[name='url']").val(result[i].url);
		       	 				element.find("input[name='info']").val(result[i].info);
		       	 			var childMenuIds=null;
		       	 			var childMenu=null;
		       	 			var childUrl=null;
		       	 			var childInfo=null;
		       	 			var childType=null;
							for (var j=i; j<result.length; j++){
								if (result[j].parentId == result[i].id){
									if(childMenuIds==null){
										childMenuIds=result[j].id;
									}else{
										childMenuIds+=','+result[j].id;
									}
								
									if(childMenu==null){
										childMenu=result[j].name;
									}else{
										childMenu+=','+result[j].name;
									}
									
									if(childUrl==null){
										childUrl=result[j].url;
									}else{
										childUrl+=','+result[j].url;
									}
									
									if(childInfo==null){
										childInfo=result[j].info;
									}else{
										childInfo+=','+result[j].info;
									}
									
									if(childType==null){
										childType=result[j].type;
									}else{
										childType+=','+result[j].type;
									}
								}
							}
							if(childMenuIds!=null){
								element.find("input[name='childMenuIds']").val(childMenuIds);
							}
							if(childMenu!=null){
								element.find("input[name='childMenu']").val(childMenu);
								initPopover(i+1);
							}
							if(childUrl!=null){
								element.find("input[name='childUrl']").val(childUrl);
							}
							if(childInfo!=null){
								element.find("input[name='childInfo']").val(childInfo);
							}
							if(childType!=null){
								element.find("input[name='childType']").val(childType);
							}
						}
						
					}
				}
	 	});
	 }
      
      function openOrclosePopover(){
      	if($("#box").prop("checked")){
      		$("#u19504_").hide();
      		$("#u19506_").hide();
      		$("#u19508_").hide();
      		$("#u19510_").hide();
      		$("#u19512_").hide();
      		bindPopover();
      	}else{
      		$("#u19504_").show();
      		$("#u19506_").show();
      		$("#u19508_").show();
      		$("#u19510_").show();
      		$("#u19512_").show();
      		unbindPopover();
      	}
      }
      
      function initPopover(i){
      //	$('[data-toggle="popover"]').each(function (i) {
		        var element = $('[data-toggle="popover"]:eq('+(i-1)+')');
		        var id = element.attr('id');
		        var txt = element.find("input[name='childMenu']").val();
		        element.popover({
		          trigger: 'manual',
		          placement: 'top', //top, bottom, left or right
		          html: 'true',
		          content: ContentMethod(txt,i),
		        }).on("mouseenter", function () {
		          var _this = this;
		          $(this).popover('show');
		          $(this).siblings(".popover").on("mouseleave", function () {
		            $(_this).popover('hide');
		          });
		        }).on("mouseleave", function () {
		          var _this = this;
		          setTimeout(function () {
		            if (!$(".popover:hover").length) {
		              $(_this).popover('hide')
		            }
		          }, 100);
		        });

		        element.popover('show');
	    //  });
      }
      
       function ContentMethod(txt,i) {
       	   var txts = txt.split(",");
       	   var html = '';
       	   if(txts.length<5){
	       	html+='<button type="button" style="width:145px;" class="btn btn-warning" data-loading-text="Loading..." onClick="addChildMenu('+i+');">添加子菜单</button></br>';
       	   }else{
	       	html+='<button type="button" style="width:145px;" class="btn btn-warning" data-loading-text="Loading...">最多5个子菜单</button></br>';
       	   }
	       $(txts).each(function(k){
	       	  if(txts!=null&&txts!=''){
	       	  	html+='<a class="btn btn-success" style="width:110px;" href="javascript:void(0);" onClick="modifyChildMenu('+i+','+k+');">'
	       				+this
	       			+'</a>'
	       			+'<a class="btn btn-danger" style="width:35px;" href="javascript:void(0);" onClick="deleteChildMenu('+i+','+k+')">'
	       				+'<i class="glyphicon glyphicon-trash"></i>'
	       			+'</a></br>';
	       	  }
	       });
      	   return html;
    	}
    	
    	//新增子菜单
	    function addChildMenu(i){
	    	$("#u19494").show();
	    	$("#u19494_").hide();
	    	$("#u19494").find("input[name='num']").val(i);
	    	$("#u19494").find("input[name='menuId']").val($("#itemId"+i).val());

	    	//初始化新增子菜单弹出框
	    	$("#u19499_input").val("");
	    	$("#u19513_input").val("");
	    	$("#u19514_input").val("");
	    	$("#u19494").find("input[name='childMenuId']").val("");
	    }
	    
	    function modifyChildMenu(i,k){
	    	$("#u19494").show();
	    	$("#u19494_").hide();
	    	$("#u19494").find("input[name='num']").val(i);
	    	$("#u19494").find("input[name='menuId']").val($("#itemId"+i).val());
	    	
	    	var ids=$("input[name='childMenuIds']:eq("+(i-1)+")").val().split(",");
	    	$("#u19494").find("input[name='childMenuId']").val(ids[k]);
	    	
	    	var names=$("input[name='childMenu']:eq("+(i-1)+")").val().split(",");
	    	var urls=$("input[name='childUrl']:eq("+(i-1)+")").val().split(",");
	    	var infos=$("input[name='childInfo']:eq("+(i-1)+")").val().split(",");
	    	var types=$("input[name='childType']:eq("+(i-1)+")").val().split(",");
	    	
	    	$("#u19499_input").val(names[k]);
	    	$("#u19514_input").val(urls[k]);
	    	$("#u19513_input").val(infos[k]);
	    	if(types[k]=='view'){
	    		changeChildToView();
	    	}else if(types[k]=='click'){
	    		changeChildToClick();
	    	}
	    }
	    
	    function deleteChildMenu(i,k){
	    	var ids=$("input[name='childMenuIds']:eq("+(i-1)+")").val().split(",");
	    	var request_url="${pageContext.request.contextPath}/menu/deleteChildMenu.action";
	    	$.get(request_url,{id:ids[k]},function(data){
	    		if(data.success){
      				alert(data.msg);
      				window.location.reload();
      			}else{
      				alert("删除子菜单失败，请联系管理员或稍后重试！");
      			}
	    	});
	    }
	    
	    function addBottomMenu(i){
	    	$("#u19494_").show();
	    	$("#num").val(i);
	    	$('[data-toggle="popover"]').unbind();
	    	//初始化新增和编辑框
	    	var span = $('[data-toggle="popover"]:eq('+(i-1)+')').find("span").html();
    		$("#u19499_input_").val(span!='+'?span:'');
    		$("#menuId").val($("#itemId"+i).val());
    		var childMenu = $('[data-toggle="popover"]:eq('+(i-1)+')').find("input[name='childMenu']").val();
    		if(childMenu!=null&&childMenu!=''){
    			if(!$("#box").prop("checked")){
    				$("#box").click();
    				bindPopover();
    			}
    		}else{
    			if($("#box").prop("checked")){
    				$("#box").click();
    				unbindPopover();
    			}
    			var type = $("#type"+i).val();
    			var url = $("#url"+i).val();
    			var info = $("#info"+i).val();
	    			$("#u19513_input_").val(info);
	    			$("#u19514_input_").val(url);
	    		if(type=='view'){
	    			changeToView();
	    		}else if(type=='click'){
	    			changeToClick();
	    		}
    		}
	    }
	    
	     function changeChildToView(){
	    	$("#u19506").css("color","black");
	    	$("#u19510").css("color","#FF00FF");
	    	$("#u19512_state1").show();
	    	$("#u19512_state0").hide();
	    }
	    
	    function changeChildToClick(){
	    	$("#u19506").css("color","#FF00FF");
	    	$("#u19510").css("color","black");
	    	$("#u19512_state0").show();
	    	$("#u19512_state1").hide();
	    }
	    
	    function changeToView(){
	    	$("#u19506_").css("color","black");
	    	$("#u19510_").css("color","#FF00FF");
	    	$("#u19512_state1_").show();
	    	$("#u19512_state0_").hide();
	    }
	    
	    function changeToClick(){
	    	$("#u19506_").css("color","#FF00FF");
	    	$("#u19510_").css("color","black");
	    	$("#u19512_state0_").show();
	    	$("#u19512_state1_").hide();
	    }
	    
	    function bindPopover(){
	    	var i=$("#num").val();
	    	initPopover(i);
	    }
	    
	    function unbindPopover(){
	    	var i=$("#num").val();
	    	var element = $('[data-toggle="popover"]:eq('+(i-1)+')');
	    	$(element).popover('hide');
	    	$(element).popover('destroy');
	    	$(element).unbind();
	    }
	    
	    function hideModel(){
	    	$("#u19494_").hide();
	    }
	    
	    function saveBottomButton(){

	    	var id = $("#menuId").val();
	    	var menuName = $("#u19499_input_").val();
	    	var info=null;
	    	var url=null;
	    	var hasChild=false;

	    	if(menuName==null||menuName==''){
	    		alert("请输入菜单名");
	    		return;
	    	}else if(getByteLen(menuName)>8){
	    		alert("一级菜单不能超过4个汉字或8个字符(一个汉字算2个字符)！");
	    		return;
	    	}
	    
	    	if($("#box").prop("checked")){
	    		if(!confirm("请添加子菜单之后保存，否则将不会保存开启子菜单状态！")){
	    			return;
	    		}
      			bindPopover();
      			hasChild=true;
      		}else{
      			if($("#u19512_state0_").css("display")!='none' && ($("#u19513_input_").val()==null||$("#u19513_input_").val()=='')){
      				alert("请输入需要发送的内容！");
      				return;
      			}else if($("#u19512_state1_").css("display")!='none' &&($("#u19514_input_").val()==null||$("#u19514_input_").val()=='') ){
      				alert("请输入需要跳转的链接！");
      				return;
      			}else if($("#u19512_state1_").css("display")!='none' &&($("#u19514_input_").val().substr(0,7)!="http://")){
      				alert("请输入以http://开头的跳转链接！");
      				return;
      			}else{
      				unbindPopover();
      			}

      			var type="";
      			if($("#u19512_state0_").css("display")!='none'){
      				type="click";
      			}else if($("#u19512_state1_").css("display")!='none'){
      				type="view";
      			}
      			info = $("#u19513_input_").val();
      			url = $("#u19514_input_").val();
      		}
      	
	    	var i=$("#num").val();
	    	$('[data-toggle="popover"]:eq('+(i-1)+')').find("span").html($("#u19499_input_").val());
	    	$.get('${pageContext.request.contextPath}/menu/saveBottomMenu.action',{id:id,menuName:menuName,type:type,info:info,url:url,hasChild:hasChild},function(data){
	    		if(data.success){
      				alert(data.msg);
      				window.location.reload();
      			}else{
      				alert("保存底部菜单失败，请联系管理员或稍后重试！");
      			}
	    	});
	    	hideModel();
	    }
	    
	    function hideModel_(){
	    	$("#u19494").hide();
	    }
	    
	    function saveChildMenu(){
	    	var menuName = $("#u19499_input").val();
	    	if(menuName==null||menuName==''){
	    		alert("请输入菜单名");
	    		return;
	    	}else if(getByteLen(menuName)>14){
	    		alert("二级菜单不能超过7个汉字或14个字符(一个汉字算2个字符)！");
	    		return;
	    	}



	    	if($("#u19512_state0").css("display")!='none' && ($("#u19513_input").val()==null||$("#u19513_input").val()=='')){
      				alert("请输入需要发送的内容！");
      				return;
      		}else if($("#u19512_state1").css("display")!='none' &&($("#u19514_input").val()==null||$("#u19514_input").val()=='') ){
      				alert("请输入需要跳转的链接！");
      				return;
      		}else if($("#u19512_state1").css("display")!='none' &&($("#u19514_input").val().substr(0,7)!="http://")){
      			alert("请输入以http://开头的跳转链接！");
      			return;
      		}
      		
      		var request_url="${pageContext.request.contextPath}/menu/saveChildMenu.action";
      		var id=$("#u19494").find("input[name='childMenuId']").val();
      		var parentId=$("#u19494").find("input[name='menuId']").val();
      		var menuName=$("#u19499_input").val();
      		
      		var type="";
      		if($("#u19512_state0").css("display")!='none'){
      			type="click";
      		}else if($("#u19512_state1").css("display")!='none'){
      			type="view";
      		}
      		
      		var url=$("#u19514_input").val();
      		var info=$("#u19513_input").val();
      		$.get(request_url,{id:id,parentId:parentId,menuName:menuName,type:type,url:url,info:info},function(data){
      			if(data.success){
      				alert(data.msg);
      				window.location.reload();
      			}else{
      				alert("添加子菜单失败，请联系管理员或稍后重试！");
      			}
      		});
      		
	    }
	    
	    function updateMenu(){
			$.ajax({
				url: '${pageContext.request.contextPath}/menu/send.action',
				type: 'post',
				success: function(result){
					if (result == 'success'){
						alert("发布成功！");
					} else {
						alert("发布失败！");
					}
				}
			});
		}

		function getByteLen(val) {
            var len = 0;
            for (var i = 0; i < val.length; i++) {
                 var a = val.charAt(i);
                 if (a.match(/[^\x00-\xff]/ig) != null)
                {
                    len += 2;
                }
                else
                {
                    len += 1;
                }
            }
            return len;
        }
</script>
  </body>
</html>

      
